package org.example.netty.demo.chapter2;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @author ： minzhiwei
 * create by 2020/1/13 19:22
 * @description
 */
public class TestServer {

    public static void main(String[] args) throws InterruptedException {
        final NioEventLoopGroup eventExecutors = new NioEventLoopGroup();
        final Channel channel = new ServerBootstrap().group(eventExecutors, eventExecutors)
                .channel(NioServerSocketChannel.class)
                .localAddress(9999)
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    protected void initChannel(SocketChannel ch) throws Exception {
                        ch.pipeline().addLast(new ChannelInboundHandler1())
                                .addLast(new ChannelInboundHandler2())
                                .addLast(new ChannelOutboundHandler1())
                                .addLast(new ChannelOutboundHandler2());
                    }
                }).bind().sync().channel();

        final ChannelFuture channelFuture = channel.closeFuture();
        channelFuture.sync();
        eventExecutors.shutdownGracefully();
    }

}
